package Fail3_17;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class FileDemo7 {

    private static void looking_for(String source, String name, List list){
        File file=new File(source);
        if(file.isFile()){
            if(file.getName().contains(name)){
                list.add(file);
            }
        }else if(file.isDirectory()){
            String[]strings=file.list();
            for (int i = 0; i < strings.length; i++) {
                looking_for(source+"/"+strings[i],name,list);
            }
        }else{

        }
    }
    public static void main(String[] args) {
        List<File>list=new ArrayList<>();
        //1.打开文件
        System.out.println("请输入您要查看的文件名");
        Scanner scanner=new Scanner(System.in);
        String s=scanner.nextLine();
        File file=new File(s);
        if(file.exists()){
            System.out.println("请输入您想要查找的文件名");
            String s1=scanner.next();
            looking_for(s,s1,list);
            for (File z:list) {
                System.out.println("请选择删除的文件");
                System.out.print(z.getName()+" ");
                String s3=scanner.next();
                if(z.getName().equals(s3)){
                    System.out.println("确认删除？"+"请输入Y/N");
                    String s7 =scanner.next();
                    if(s7.equals("Y"))
                    {
                        z.delete();
                    }
                }
            }
        }else {
            System.out.println("您输入的文件名不对");
        }
    }
}
